package com.kvest.view_pager_test.FragmentDialog;

import android.app.AlertDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;

/**
 * Created with IntelliJ IDEA.
 * User: Kvest
 * Date: 17.03.13
 * Time: 23:50
 * To change this template use File | Settings | File Templates.
 */
public class DialogUsingCreator extends DialogFragment {
    private static final String SELECTED_ITEM_EXTRA = "selected_item";
    private String selectedItem;

    public DialogUsingCreator() {
        this("?");
    }

    public DialogUsingCreator(String selectedItem) {
        super();
        this.selectedItem = selectedItem;
    }

    @Override
    public void onCreate(Bundle savedState) {
        super.onCreate(savedState);
        if (savedState != null && savedState.containsKey(SELECTED_ITEM_EXTRA)) {
            selectedItem = savedState.getString(SELECTED_ITEM_EXTRA);
        }
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setTitle("Заголовок");
        builder.setMessage("Selected: " + selectedItem);
        builder.setNegativeButton("Cancel", null);
        builder.setPositiveButton("Ok", null);
        return builder.create();
    }

    @Override
    public void onSaveInstanceState(Bundle savedState) {
        super.onSaveInstanceState(savedState);
        savedState.putString(SELECTED_ITEM_EXTRA, selectedItem);
    }
}
